package com.cbl.v.ssczs.view.activity;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.Toolbar;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.cbl.v.ssczs.R;
import com.cbl.v.ssczs.mode.util.ActivityGroup;
import com.cbl.v.ssczs.mode.util.GlideImageLoader;
import com.cbl.v.ssczs.view.agent.MarqueeView;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 时时彩走势至尊版
 */
public class KlsfActivity extends BaseActivity {
    @BindView(R.id.banner)
    Banner banner;
    @BindView(R.id.tv_dlt)
    TextView tv_dlt;
    @BindView(R.id.tv_qxc)
    TextView tv_qxc;
    @BindView(R.id.tv_pl3)
    TextView tv_pl3;
    @BindView(R.id.tv_pl5)
    TextView tv_pl5;
    @BindView(R.id.tv_ssq)
    TextView tv_ssq;
    @BindView(R.id.tv_fc3d)
    TextView tv_fc3d;
    private Intent intent;
    private MarqueeView tv_marguee;
    private TextView title_right;

    @Override
    protected int getLayout() {
        return R.layout.activity_chart;
    }

    @Override
    public void initView() {
        hideTitleBar();
        tv_marguee = (MarqueeView) findViewById(R.id.marqueeView);
        initMarqueeText();
        initBanner();
        initToolBar();
    }

    private void initToolBar() {
        Toolbar toolBar = (Toolbar) findViewById(R.id.toolbar);
        TextView title_name = (TextView) findViewById(R.id.title_name);
         title_right = (TextView) findViewById(R.id.title_right);
        title_name.setText("快乐十分-工具箱");
        title_right.setVisibility(View.VISIBLE);
        toolBar.setTitle("");
        toolBar.setTitleTextColor(Color.WHITE);
    }


    private void initMarqueeText() {

        List<CharSequence> list = new ArrayList<>();
        SpannableString ss1 = new SpannableString("　　　　　公告！公告！公告！公告！");
        ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, ss1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        list.add(ss1);
        SpannableString ss2 = new SpannableString("　　　　现已禁止网上销售彩票内业务！");
        ss2.setSpan(new ForegroundColorSpan(Color.MAGENTA), 0, ss1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        list.add(ss2);
        SpannableString ss3 = new SpannableString("　　　如有需要,请到附近相关的实体店进行选彩！");
        list.add(ss3);
        SpannableString ss4 = new SpannableString("　　　　 请广大彩民遵纪守法切勿上当受骗！");
        ss4.setSpan(new ForegroundColorSpan(Color.MAGENTA), 10, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        list.add(ss4);
        // 在代码里设置自己的动画
        tv_marguee.startWithList(list, R.anim.anim_bottom_in, R.anim.anim_top_out);
    }

    private void initBanner() {
        List<Integer> images = new ArrayList<>();
        images.add(R.drawable.banner_1);
        images.add(R.drawable.banner_2);
        images.add(R.drawable.banner_3);

        banner = (Banner) findViewById(R.id.banner);
        //设置banner样式
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        //设置图片集合
        banner.setImages(images);
        //设置图片加载器
        banner.setImageLoader(new GlideImageLoader());
        //设置banner动画效果
        banner.setBannerAnimation(Transformer.Default);
        //设置自动轮播，默认为true
        banner.isAutoPlay(true);
        //设置轮播时间
        banner.setDelayTime(1500);
        //设置指示器位置（当banner模式中有指示器时）
        banner.setIndicatorGravity(BannerConfig.CENTER);
        //banner设置方法全部调用完毕时最后调用
        banner.start();

    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {
        title_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent = new Intent();
                intent.setClass(KlsfActivity.this, AboutUsActivity.class);
                startActivity(intent);
            }
        });
    }

    @OnClick({R.id.tv_dlt, R.id.tv_qxc, R.id.tv_pl3, R.id.tv_pl5, R.id.tv_ssq, R.id.tv_fc3d})
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_dlt:
                intent = new Intent();
                intent.setClass(this, KlsfForAllActivity.class);
                intent.putExtra("url", "http://m.500.com/info/index.php?c=zhongjiang&a=dlt&");
                intent.putExtra("type", "超级大乐透");
                startActivity(intent);
                break;
            case R.id.tv_qxc:
                intent = new Intent();
                intent.setClass(this, KlsfForAllActivity.class);
                intent.putExtra("url", "http://m.500.com/info/index.php?c=zhongjiang&a=ssq&");
                intent.putExtra("type", "双色球");
                startActivity(intent);
                break;
            case R.id.tv_pl3:
                intent = new Intent();
                intent.setClass(this, KlsfForAllActivity.class);
                intent.putExtra("url", "http://m.500.com/info/index.php?c=zhongjiang&a=sfc&");
                intent.putExtra("type", "胜负彩");
                startActivity(intent);
                break;
            case R.id.tv_pl5:
                intent = new Intent();
                intent.setClass(this, KlsfForAllActivity.class);
                intent.putExtra("url", "http://m.500.com/info/index.php?c=zhongjiang&a=rj&");
                intent.putExtra("type", "任选九");
                startActivity(intent);
                break;
            case R.id.tv_ssq:
                intent = new Intent();
                intent.setClass(this, KlsfForAllActivity.class);
                intent.putExtra("url", "http://m.500.com/chart/ssq/yilou.html");
                intent.putExtra("type", "双色球");
                startActivity(intent);
                break;
            case R.id.tv_fc3d:
                intent = new Intent();
                intent.setClass(this, KlsfForAllActivity.class);
                intent.putExtra("url", "http://m.500.com/chart/3d/zhixuan.htm");
                intent.putExtra("type", "福彩3D");
                startActivity(intent);
                break;
        }
    }

    //如果你需要考虑更好的体验，可以这么操作
    @Override
    protected void onStart() {
        super.onStart();
        //开始轮播
        banner.startAutoPlay();
        tv_marguee.startFlipping();
    }

    @Override
    protected void onStop() {
        super.onStop();
        //结束轮播
        banner.stopAutoPlay();
        tv_marguee.stopFlipping();
    }


    private long lastBackPress;

    @Override
    public void onBackPressed() {
        if (System.currentTimeMillis() - lastBackPress < 1000) {
            ActivityGroup.finishAllActivity();
            android.os.Process.killProcess(android.os.Process.myPid());
            super.onBackPressed();
        } else {
            lastBackPress = System.currentTimeMillis();
            Toast.makeText(KlsfActivity.this, "再按一次退出", Toast.LENGTH_SHORT).show();
        }
    }
}
